package com.dongdongshop.serviceimpl;

import com.dongdongshop.mapper.TbContentMapper;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    private TbContentMapper tbContentMapper;
    //查询广告管理所有
    @Override
    public List<TbContent> findallContent() {
        List<TbContent> tbContents = tbContentMapper.selectByExample(null);
        return tbContents;
    }

    //增加
    @Override
    public Boolean insertContent(TbContent tbContent) {
        try {
            int i = tbContentMapper.insertSelective(tbContent);
            if (i>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //回显
    @Override
    public TbContent selectContentById(Long id) {
        TbContent tbContent = tbContentMapper.selectByPrimaryKey(id);
        return tbContent;
    }

    //修改
    @Override
    public Boolean updateContent(TbContent tbContent) {
        try {
            int i = tbContentMapper.updateByPrimaryKeySelective(tbContent);
            if (i>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //删除
    @Override
    public Boolean deleteContent(Long[] ids) {
        try {
            for (int i = 0; i < ids.length; i++) {
                tbContentMapper.deleteByPrimaryKey(ids[i]);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //排序查询轮播图
    @Override
    public List<TbContent> selectContentDesc(Long categoryId) {
        List<TbContent> list = tbContentMapper.selectContentDesc(categoryId);
        return list;
    }
}
